package test04.sync.test06;

/**
 *
 * 银行帐号
 * @Author lzp
 * @Date 2024-03-21
 */
public class Account {

    private double money;

    public Account() {
    }
    public Account(double money) {
        this.money =money;
    }

    public synchronized void getMoney(String name,double money){
        System.out.println(name + "取" + money + "元");

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        if (this.money > money){
            this.money = this.money -money;
            System.out.println("还剩" + this.money);
            return;
        }
        System.out.println("余额不足,还剩" + this.money);
    }
}
